package com.example.demo;



import okhttp3.*;

import java.io.File;
import java.io.IOException;

/**
 * Client
 *
 * @author 黄泽涛
 * @date 2021/12/30 18:56
 * @
 **/

public class httpClient {

    public void uploadFile(String fileUrl,String httpUrl){
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("text/plain");
        RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("file","/E:/1.txt",
                        RequestBody.create(MediaType.parse("application/octet-stream"),
                                new File("/E:/1.txt")))
                .build();
        Request request = new Request.Builder()
                .url("http://127.0.0.1:8080/file/fileUpload")
                .method("POST", body)
                .build();
        try {
            Response response = client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //http://127.0.0.1:8080/file/fileDownLoad?fileName=05871f68-88ed-417a-851e-fa34537e6dac
    public void downLoadFile(String url){
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        Request request = new Request.Builder()
                .url(url)
                .method("GET", null)
                .build();
        try {
            Response response = client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //http://127.0.0.1:8080/file/getFileInformation?fileName=05871f68-88ed-417a-851e-fa34537e6dac
    public void getInformation(String url){
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        Request request = new Request.Builder()
                .url(url)
                .method("GET", null)
                .build();
        try {
            Response response = client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

    }

}
